package com.yjf.ljr.activity;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.CheckedTextView;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.yjf.ljr.R;
import com.yjf.ljr.activity.AddBankCardActivity.ViewHolder;
import com.yjf.ljr.activity.IjActivity.ID;
import com.yjf.ljr.activity.RegistrationActivity.RegisterSubmitTask;
import com.yjf.ljr.activity.RegistrationActivity.SendSmsCodeTask;
import com.yjf.ljr.activity.RegistrationActivity.VerifyRefereesTask;
import com.yjf.ljr.adapter.CommonAdapter;
import com.yjf.ljr.adapter.CommonAdapter.HandleCallBack;
import com.yjf.ljr.dataclass.AreaDataClass;
import com.yjf.ljr.dataclass.IdentityInfoDataClass;
import com.yjf.ljr.dataclass.OpenAccountDataClass;
import com.yjf.ljr.dataclass.SendSmsCodeDataClass;
import com.yjf.ljr.dataclass.VerifySmsCodeDataClass;
import com.yjf.ljr.dataclass.IdentityInfoDataClass.IdentityInfo;
import com.yjf.ljr.dataclass.OpenAccountDataClass.AreaInfo;
import com.yjf.ljr.dataclass.OpenAccountDataClass.BankInfo;
import com.yjf.ljr.parser.RequestBuilder.RequestObject;
import com.yjf.ljr.util.AESUtil;
import com.yjf.ljr.util.AppUtil;
import com.yjf.ljr.util.PicLoad;
import com.yjf.ljr.util.AppUtil.HandlerItemCallBack;
import com.yjf.ljr.util.SPreferences;

public class RegistrationActiveActivity extends IjActivity implements OnClickListener{

	@ID("active_container")
	private LinearLayout activeContainer;
	@ID("phone_num")
	private EditText phoneNum;
	@ID("real_name")
	private EditText realName;
	@ID("ID_num")
	private EditText IDNum;
	@ID("withdraw_pwd")
	private EditText withdrawPwd;
	@ID("payuser_name")
	private EditText payuserName;
	@ID("bank_num")
	private EditText bankNum;
	@ID("bank_name")
	private TextView bankName;
	@ID("bank_province")
	private TextView bankProvince;
	@ID("bank_city")
	private TextView bankCity;
	@ID("avtive_btn")
	private Button avtiveBtn;
	@ID("btnGetVerifyCode")
	private Button btnGetVerifyCode;
	@ID("etVerifyCode")
	private EditText etVerifyCode;
	@ID("payuer_tip")
	private TextView payuerTip;
	@ID("verifyCodeContainer")
	private FrameLayout verifyCodeContainer;
	@ID("bank_tip")
	private TextView bankTip;

	private String phoneNumStr;
	private String userName;

	private PopupWindow chooseBankPop;
	private PopupWindow chooseProvincePop;
	private PopupWindow chooseCityPop;


	private CommonAdapter bankAdapter;
	private CommonAdapter provinceAdapter;
	private CommonAdapter cityAdapter;
	private List<BankInfo> mBankInfos = new ArrayList<BankInfo>();
	private List<AreaInfo> province = new ArrayList<AreaInfo>();
	private List<AreaInfo> city = new ArrayList<AreaInfo>();

	private BankInfo selectedBankInfo;
	private AreaInfo selectedProvinceInfo;
	private AreaInfo selectedCityInfo;

	private int REQUEST_REGISTRATION_OK = 1;

	private String personrealName;
	private String IDNumber;


	private Handler mHandler = new Handler() {
		public void handleMessage(Message msg) {
			int time = (Integer) msg.obj;
			btnGetVerifyCode.setText(String.format("%02d秒", time));
			if (time-- > 0) {
				mHandler.sendMessageDelayed(mHandler.obtainMessage(0, time), 1000);
			} else {
				btnGetVerifyCode.setBackgroundResource(R.drawable.verification_selector);
				btnGetVerifyCode.setClickable(true);
				btnGetVerifyCode.setText("获取验证码");
			}
		}
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_registration_active);
		initContent();
		new OpenAccountTask().execute();
		new IdentityInfoTask().execute();
	}

	private void initContent() {
		setTitleStr("开通支付账户");
		setLeftBtnClick();
		avtiveBtn.setOnClickListener(this);
		bankCity.setOnClickListener(this);
		bankProvince.setOnClickListener(this);
		bankName.setOnClickListener(this);
		phoneNumStr = getIntent().getStringExtra("phoneNum");
		userName = SPreferences.getUserName(this);
		if(!TextUtils.isEmpty(userName)) {
			phoneNum.setText(userName);
			phoneNum.setEnabled(false);
		}
		if(!TextUtils.isEmpty(phoneNumStr)) {
			payuserName.setText(phoneNumStr);
		}

		bankAdapter = new CommonAdapter(RegistrationActiveActivity.this, mBankInfos,
				R.layout.item_text_popmenu, ViewHolder.class, mHandleCallBackBank);
		chooseBankPop = AppUtil.getPopupWindow(mContext, bankAdapter, "请选择银行", new HandlerItemCallBack() {

			@Override
			public void handle(AdapterView<?> parent, View view, int position, long id) {
				BankInfo info = mBankInfos.get(position);
				selectedBankInfo = info;
				bankName.setText(info.bankName);
			}
		});

		provinceAdapter = new CommonAdapter(RegistrationActiveActivity.this, province,
				R.layout.item_popmenu_area, AreaViewHolder.class, mAreaCallBack);
		chooseProvincePop = AppUtil.getPopupWindow(mContext, provinceAdapter,"请选择开户银行所在省", new HandlerItemCallBack() {

			@Override
			public void handle(AdapterView<?> parent, View view, int position, long id) {
				AreaInfo info = province.get(position);
				selectedProvinceInfo = info;
				bankProvince.setText(info.province);
			}
		});

		cityAdapter = new CommonAdapter(RegistrationActiveActivity.this, city,
				R.layout.item_popmenu_area, AreaViewHolder.class, mCityCallBack);
		chooseCityPop = AppUtil.getPopupWindow(mContext, cityAdapter,"请选择开户银行所在市", new HandlerItemCallBack() {

			@Override
			public void handle(AdapterView<?> parent, View view, int position, long id) {
				AreaInfo info = city.get(position);
				selectedCityInfo = info;
				bankCity.setText(info.city);
			}
		});

		btnGetVerifyCode.setOnClickListener(this);
		payuserName.addTextChangedListener(new TextWatcher(){

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count, int after) {

			}

			@Override
			public void onTextChanged(CharSequence s, int start, int before, int count) {

			}

			@Override
			public void afterTextChanged(Editable s) {
				judgeVerifyCodeContainer();
			}

		});

		judgeVerifyCodeContainer();

		realName.setOnFocusChangeListener(new OnFocusChangeListener() {

			@Override
			public void onFocusChange(View v, boolean hasFocus) {
				if(!hasFocus) {
					judgeBankTipShow();
				}

			}
		});
	}

	@Override
	public void onClick(View v) {
		switch(v.getId()) {
			case R.id.avtive_btn:
				String mobileStr = phoneNum.getText().toString().trim();
				String realNameStr = realName.getText().toString().trim();
				String IDNumStr = IDNum.getText().toString().trim().toUpperCase();
				String withdrawPwdStr = withdrawPwd.getText().toString().trim();
				String bankNumStr = bankNum.getText().toString().trim();
				String payuserNameStr = payuserName.getText().toString().trim();
				String etVerifyCodeStr = etVerifyCode.getText().toString().trim();

				if(TextUtils.isEmpty(mobileStr)) {
					showToast("请输入平台用户名！");
					return;
				}
//			if(!AppUtil.isMobileNO(mobileStr)) {
//				showToast("手机号码格式不正确！");
//				return;
//			}
				if(!AppUtil.isMobileNO(payuserNameStr)) {
					showToast("支付账户名错误，请输入手机号");
					return;
				}

				if(!payuserNameStr.equals(phoneNumStr)) {
					if(TextUtils.isEmpty(etVerifyCodeStr)) {
						showToast("请输入验证码");
						return;
					}
				}

				if(TextUtils.isEmpty(realNameStr)) {
					showToast("请输入真实姓名！");
					return;
				}
				if(TextUtils.isEmpty(IDNumStr)) {
					showToast("请输入身份证号码!");
					return;
				}

				if(IDNumStr.length() != 18) {
					showToast("请输入正确的身份证号码！");
					return;
				}

				if(TextUtils.isEmpty(withdrawPwdStr)) {
					showToast("请输入支付密码！");
					return;
				}

				if (AppUtil.isChinese(withdrawPwdStr)) {
					showToast("密码不能包含中文");
					return;
				}

				if(withdrawPwdStr.contains(" ")) {
					showToast("提现密码应为字母和数字的组合，不能有空格！");
					return;
				}

				if(AppUtil.isNumeric(withdrawPwdStr)) {
					showToast("提现密码应为字母和数字的组合!");
					return;
				}
				if(!AppUtil.hasDigit(withdrawPwdStr)) {
					showToast("提现密码应为字母和数字的组合!");
					return;
				}

				if(withdrawPwdStr.length() < 6 || withdrawPwdStr.length() > 16) {
					showToast("请输入6-16位提现密码！");
					return;
				}
				if(TextUtils.isEmpty(bankNumStr)) {
					showToast("请输入银行卡号！");
					return;
				}
				if(selectedBankInfo == null) {
					showToast("请选择开户银行名称！");
					return;
				}
				if(selectedProvinceInfo == null) {
					showToast("请选择开户银行所在省！");
					return;
				}
				if(selectedCityInfo == null) {
					showToast("请选择开户银行所在市1");
					return;
				}
				if(TextUtils.isEmpty(etVerifyCodeStr)) {
					showProgressDialog();
					new OpenAccountSubmitTask(mobileStr,payuserNameStr,realNameStr,IDNumStr,AESUtil.encode(withdrawPwdStr),bankNumStr,selectedBankInfo.bankCode,selectedCityInfo.cityNo,null).execute();
				} else {
					new VerifySmsCodeTask(mobileStr,payuserNameStr,realNameStr,IDNumStr,AESUtil.encode(withdrawPwdStr),bankNumStr,selectedBankInfo.bankCode,selectedCityInfo.cityNo,etVerifyCodeStr).execute();
				}

				break;
			case R.id.bank_name:
				if(mBankInfos == null || mBankInfos.size() < 1) {
					new BankListTask().execute();
				} else {
					if(chooseBankPop != null && !chooseBankPop.isShowing()) {
						chooseBankPop.showAtLocation(realName, Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL, 0, 0);
					}
				}
				break;
			case R.id.bank_province:
				if(province == null || province.size() < 1) {
					new AreaListTask().execute();
				} else {
					if(chooseProvincePop != null && !chooseProvincePop.isShowing()) {
						chooseProvincePop.showAtLocation(realName, Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL, 0, 0);
					}
				}
				bankCity.setText("");
				selectedCityInfo = null;
				break;
			case R.id.bank_city:
				if(selectedProvinceInfo == null) {
					showToast("请选择省份");
					return;
				}
				new CityListTask(selectedProvinceInfo.provinceNo).execute();
				break;
			case R.id.btnGetVerifyCode:
				String phoneNum = payuserName.getText().toString();
				if (TextUtils.isEmpty(phoneNum)) {
					showToast("请输入手机号");
					return;
				}
				if (!AppUtil.isMobileNO(phoneNum)) {
					showToast("手机号码格式不符");
					return;
				}
				showProgressDialog();
				new SendSmsCodeTask(phoneNum).execute();

				btnGetVerifyCode.setBackgroundResource(R.drawable.shape_btn_gray_bg);
				btnGetVerifyCode.setClickable(false);
				mHandler.sendMessageDelayed(mHandler.obtainMessage(0, 60), 0);
				break;
		}
	}


	public static class AreaViewHolder {
		CheckedTextView text;
	}

	private HandleCallBack mHandleCallBackBank = new HandleCallBack() {

		@SuppressWarnings("unchecked")
		@Override
		public void handle(int position, View convertView, ViewGroup parent, Object holder, Object item) {
			final ViewHolder v = (ViewHolder) holder;
			BankInfo info = (BankInfo) item;
			v.tvBankName.setText(info.bankName);
			PicLoad.getImage(v.ivBankLogo, info.logoUrl);
		}

	};

	private HandleCallBack mAreaCallBack = new HandleCallBack() {
		@SuppressWarnings("unchecked")
		@Override
		public void handle(int position, View convertView, ViewGroup parent, Object holder, Object item) {
			final AreaViewHolder v = (AreaViewHolder) holder;
			AreaInfo info = (AreaInfo) item;
			v.text.setText(info.province);
		}
	};


	private HandleCallBack mCityCallBack = new HandleCallBack() {
		@SuppressWarnings("unchecked")
		@Override
		public void handle(int position, View convertView, ViewGroup parent, Object holder, Object item) {
			final AreaViewHolder v = (AreaViewHolder) holder;
			AreaInfo info = (AreaInfo) item;
			v.text.setText(info.city);
		}
	};

	class OpenAccountTask extends AsyncTask<Void, Void, String> {
		OpenAccountDataClass dc = new OpenAccountDataClass();

		@Override
		protected void onPreExecute() {
			super.onPreExecute();
			showProgressDialog();
		}

		@Override
		protected String doInBackground(Void... arg0) {
			RequestObject mObject = new RequestObject();
			mObject.method = "openAccount";
			return requestDataAndGetErrorMsg(mObject, dc);
		}

		@Override
		protected void onPostExecute(String result) {
			super.onPostExecute(result);
			dismissProgressDialog();
			if ("-1".equals(dc.code)) {
				loginWebview();
				return;
			}
			if (!TextUtils.isEmpty(result)) {// fail
				showToast(result);
			} else {// success
				mBankInfos.clear();
				mBankInfos.addAll(dc.bankList);
				bankAdapter.notifyDataSetChanged();
			}
		}
	}

	class OpenAccountSubmitTask extends AsyncTask<Void, Void, String> {
		OpenAccountDataClass dc = new OpenAccountDataClass();

		private String mobileStr;
		private String realNameStr;
		private String IDNumStr;
		private String withdrawPwdStr;
		private String bankNumStr;
		private String bankCodeStr;
		private String cityCodeStr;
		private String payuserNameStr;
		private String smsCode;

		public OpenAccountSubmitTask(String mobileStr,String payuserNameStr,String realNameStr,String IDNumStr,String withdrawPwdStr,
									 String bankNumStr, String bankCodeStr, String cityCodeStr,String smsCode) {
			this.mobileStr = mobileStr;
			this.realNameStr = realNameStr;
			this.IDNumStr = IDNumStr;
			this.withdrawPwdStr = withdrawPwdStr;
			this.bankCodeStr = bankCodeStr;
			this.bankNumStr = bankNumStr;
			this.cityCodeStr = cityCodeStr;
			this.payuserNameStr = payuserNameStr;
			this.smsCode = smsCode;
		}

		@Override
		protected void onPreExecute() {
			super.onPreExecute();
		}

		@Override
		protected String doInBackground(Void... arg0) {
			RequestObject mObject = new RequestObject();
			mObject.method = "openAccountSubmit";
			String nameStr = realNameStr;
			try {
				nameStr = URLEncoder.encode(realNameStr, "utf-8");
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
			String pwdStr = withdrawPwdStr;
			try {
				pwdStr = URLEncoder.encode(withdrawPwdStr, "utf-8");
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
			mObject.map.put("realName", nameStr);
			mObject.map.put("certNo", IDNumStr);
			mObject.map.put("accountName", payuserNameStr);
			mObject.map.put("payPassword", pwdStr);
			mObject.map.put("bankCardNo", bankNumStr);
			mObject.map.put("bankCode", bankCodeStr);
			mObject.map.put("cityNo", cityCodeStr);
			if(!TextUtils.isEmpty(smsCode)) {
				mObject.map.put("code", smsCode);
			}

			return requestDataAndGetErrorMsg(mObject, dc);
		}

		@Override
		protected void onPostExecute(String result) {
			super.onPostExecute(result);
			dismissProgressDialog();
			if ("-1".equals(dc.code)) {
				loginWebview();
				return;
			}
			if (!TextUtils.isEmpty(result)) {// fail
				showToast(result);
			} else {// success
				Intent intent = new Intent(RegistrationActiveActivity.this,RegistrationActiveOKActivity.class);
				startActivityForResult(intent, REQUEST_REGISTRATION_OK);
			}
		}
	}


	class AreaListTask extends AsyncTask<Void, Void, String> {
		AreaDataClass dc = new AreaDataClass();

		@Override
		protected void onPreExecute() {
			super.onPreExecute();
			showProgressDialog();
		}

		@Override
		protected String doInBackground(Void... arg0) {
			RequestObject mObject = new RequestObject();
			mObject.method = "areaList";
			return requestDataAndGetErrorMsg(mObject, dc);
		}

		@Override
		protected void onPostExecute(String result) {
			super.onPostExecute(result);
			dismissProgressDialog();
			if ("-1".equals(dc.code)) {
				loginWebview();
				return;
			}
			if (!TextUtils.isEmpty(result)) {// fail
				showToast(result);
			} else {// success
				province.clear();
				province.addAll(dc.list);
				provinceAdapter.notifyDataSetChanged();
				if(province.size() > 0 && chooseProvincePop != null && !chooseProvincePop.isShowing()) {
					chooseProvincePop.showAtLocation(realName, Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL, 0, 0);
				}
			}
		}
	}

	class CityListTask extends AsyncTask<Void, Void, String> {
		AreaDataClass dc = new AreaDataClass();

		private String provinceNo;
		public CityListTask(String provinceNo) {
			this.provinceNo = provinceNo;
		}

		@Override
		protected void onPreExecute() {
			super.onPreExecute();
			showProgressDialog();
		}

		@Override
		protected String doInBackground(Void... arg0) {
			RequestObject mObject = new RequestObject();
			mObject.method = "cityList";
			mObject.map.put("provinceNo", provinceNo);
			return requestDataAndGetErrorMsg(mObject, dc);
		}

		@Override
		protected void onPostExecute(String result) {
			super.onPostExecute(result);
			dismissProgressDialog();
			if ("-1".equals(dc.code)) {
				loginWebview();
				return;
			}
			if (!TextUtils.isEmpty(result)) {// fail
				showToast(result);
			} else {// success
				city.clear();
				city.addAll(dc.list);
				cityAdapter.notifyDataSetChanged();
				if(city.size() > 0 && chooseCityPop != null && !chooseCityPop.isShowing()) {
					chooseCityPop.showAtLocation(realName, Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL, 0, 0);
				}
			}
		}
	}

	class BankListTask extends AsyncTask<Void, Void, String> {
		OpenAccountDataClass dc = new OpenAccountDataClass();

		@Override
		protected void onPreExecute() {
			super.onPreExecute();
			showProgressDialog();
		}

		@Override
		protected String doInBackground(Void... arg0) {
			RequestObject mObject = new RequestObject();
			mObject.method = "getBankInfo";
			return requestDataAndGetErrorMsg(mObject, dc);
		}

		@Override
		protected void onPostExecute(String result) {
			super.onPostExecute(result);
			dismissProgressDialog();
			if ("-1".equals(dc.code)) {
				loginWebview();
				return;
			}
			if (!TextUtils.isEmpty(result)) {// fail
				showToast(result);
			} else {// success
				mBankInfos.clear();
				mBankInfos.addAll(dc.bankList);
				bankAdapter.notifyDataSetChanged();
				if(chooseBankPop != null && !chooseBankPop.isShowing()) {
					chooseBankPop.showAtLocation(realName, Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL, 0, 0);
				}
			}
		}
	}


	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
		setResult(RESULT_OK);
		finish();
	}

	public void judgeVerifyCodeContainer() {
		String payuserNameStr = payuserName.getText().toString().trim();
		if(payuserNameStr.equals(phoneNumStr)) {
			verifyCodeContainer.setVisibility(View.GONE);
			payuerTip.setVisibility(View.VISIBLE);
			etVerifyCode.setText("");
			mHandler.removeMessages(0);
			mHandler.sendMessageDelayed(mHandler.obtainMessage(0, 0), 0);
		} else {
			verifyCodeContainer.setVisibility(View.VISIBLE);
			payuerTip.setVisibility(View.GONE);
		}
	}

	public void judgeBankTipShow() {
		String name = realName.getText().toString().trim();
		if(!TextUtils.isEmpty(name)) {
			bankTip.setText(getString(R.string.bank_tip, name));
			bankTip.setVisibility(View.VISIBLE);
		} else {
			bankTip.setVisibility(View.GONE);
		}
	}

	public PopupWindow getAreaPopupWindow(Context ctx, final CommonAdapter adapter,
										  final HandlerItemCallBack handlerItemCallBack) {
		View v = View.inflate(ctx, R.layout.popmenu_area, null);
		WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);

		int width = wm.getDefaultDisplay().getWidth();
		int spaceWidth = AppUtil.dip2px(ctx,50);
		width = (width-spaceWidth)/2;
		final PopupWindow popMenu = new PopupWindow(v, width, LayoutParams.WRAP_CONTENT);
		ListView lvPopMenu = (ListView) v.findViewById(R.id.lvArea);
		lvPopMenu.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				handlerItemCallBack.handle(parent, view, position, id);
				popMenu.dismiss();
			}
		});
		v.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				popMenu.dismiss();
			}
		});
		lvPopMenu.setAdapter(adapter);

		popMenu.setFocusable(true);
		popMenu.setOutsideTouchable(true);
		popMenu.update();
		popMenu.setBackgroundDrawable(new BitmapDrawable());
		return popMenu;
	}

	class SendSmsCodeTask extends AsyncTask<Void, Void, String> {

		private String mobile;// 电话号码
		private SendSmsCodeDataClass dc = new SendSmsCodeDataClass();

		public SendSmsCodeTask(String mobile) {
			this.mobile = mobile;
		}

		@Override
		protected String doInBackground(Void... arg0) {
			RequestObject requestObject = new RequestObject();
			requestObject.method = "sendSmsCode";
			requestObject.map.put("mobile", mobile);
			requestObject.map.put("business", "accountOpen");
			return requestDataAndGetErrorMsg(requestObject, dc);
		}

		@Override
		protected void onPostExecute(String result) {
			if (!TextUtils.isEmpty(result)) {
				showToast(result);
			} else {
				if ("1".equals(dc.code)) {
					showToast("验证码已发送，请注意查收");
				}
			}
			dismissProgressDialog();
		}
	}


	class VerifySmsCodeTask extends AsyncTask<Void, Void, String> {
		VerifySmsCodeDataClass dc = new VerifySmsCodeDataClass();
		private String mobileStr;
		private String realNameStr;
		private String IDNumStr;
		private String withdrawPwdStr;
		private String bankNumStr;
		private String bankCodeStr;
		private String cityCodeStr;
		private String payuserNameStr;
		private String verifyCode;

		public VerifySmsCodeTask(String mobileStr,String payuserNameStr,String realNameStr,String IDNumStr,String withdrawPwdStr,
								 String bankNumStr, String bankCodeStr, String cityCodeStr,String verifyCode) {
			this.mobileStr = mobileStr;
			this.realNameStr = realNameStr;
			this.IDNumStr = IDNumStr;
			this.withdrawPwdStr = withdrawPwdStr;
			this.bankCodeStr = bankCodeStr;
			this.bankNumStr = bankNumStr;
			this.cityCodeStr = cityCodeStr;
			this.payuserNameStr = payuserNameStr;
			this.verifyCode = verifyCode;
		}

		@Override
		protected void onPreExecute() {
			super.onPreExecute();
			showProgressDialog();
		}

		@Override
		protected String doInBackground(Void... params) {
			// TODO Auto-generated method stub
			RequestObject mObject = new RequestObject();
			mObject.method = "verifySmsCode";
			mObject.map.put("mobile", payuserNameStr);
			mObject.map.put("code", verifyCode);
			mObject.map.put("business", "accountOpen");
			return requestDataAndGetErrorMsg(mObject, dc);
		}

		@Override
		protected void onPostExecute(String result) {
			// TODO Auto-generated method stub
			super.onPostExecute(result);
			if (!TextUtils.isEmpty(result)) {// fail
				showToast(result);
				dismissProgressDialog();
			} else {// success
				new OpenAccountSubmitTask(mobileStr,payuserNameStr,realNameStr,IDNumStr,withdrawPwdStr,bankNumStr,selectedBankInfo.bankCode,selectedCityInfo.cityNo,verifyCode).execute();
			}

		}

	}

	class IdentityInfoTask extends AsyncTask<Void, Void, String> {
		private String mFailStr;
		private IdentityInfoDataClass dc = new IdentityInfoDataClass();

		@Override
		protected void onPreExecute() {
			super.onPreExecute();
		}

		@Override
		protected String doInBackground(Void... params) {
			RequestObject mObject = new RequestObject();
			mObject.method = "getRealNameInfo";
			return requestDataAndGetErrorMsg(mObject, dc);
		}

		@Override
		protected void onPostExecute(String result) {
			dismissProgressDialog();
			if ("-1".equals(dc.code)) {
				return;
			}
			if (TextUtils.isEmpty(result)) {
				IdentityInfo data = dc.identityInfo;
				if (data != null) {
					personrealName = data.realName;// 真实姓名
					IDNumber = data.realCertNo;// 身份证号
					realName.setText(personrealName);
					IDNum.setText(IDNumber);
					judgeBankTipShow();
				}
			}
		}
	}


	@Override
	protected void onDestroy() {
		if(chooseBankPop != null && chooseBankPop.isShowing()) {
			chooseBankPop.dismiss();
		}
		if(chooseProvincePop != null && chooseProvincePop.isShowing()) {
			chooseProvincePop.dismiss();
		}
		if(chooseCityPop != null && chooseCityPop.isShowing()) {
			chooseCityPop.dismiss();
		}
		super.onDestroy();
	}

}
